﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EasyClassUI.forms.group;
using EasyClassUI.entity;
using EasyClassUI.WebRequest;

namespace EasyClassUI.forms.blog
{
    public partial class blogIndexCell : UserControl
    {
        private Post post;
        public blogIndexCell(string blogName, string username, string contentInShort, int likeCount, int commentCount, Post post)
        {
            // 初始化cell以及信息
            InitializeComponent();
            NamePostTitleLabel.Text = blogName;
            UserNameLabel.Text = username;
            PostDescribeLabel.Text = contentInShort;
            likeCountLabel.Text = likeCount.ToString();
            CommentCountLabel.Text = commentCount.ToString();
            this.post = post;
        }

        bool ifLiked = false;
        private void likePictureBox_Click(object sender, EventArgs e)
        {
            ifLiked = !ifLiked;
            if (ifLiked) 
            {
                likePictureBox.Image = Properties.Resources.like;
                //数据库点赞数+1
                PostService postService = new PostService();
                postService.LikePost(post.PostID.ToString());
                likeCountLabel.Text = (int.Parse(likeCountLabel.Text) + 1).ToString();
            }
            else
            {
                likePictureBox.Image = Properties.Resources.like_default;
                //数据库点赞数-1
            }

        }

        private void NamePostTitleLabel_Click(object sender, EventArgs e) {
            blogDetailShow bds = new blogDetailShow(post);
            bds.Show();


        }
    }
}
